﻿function getParams() {
    var params = {};

    var companyName = $("input[name='companyName']").val()
    if (!FlashPay.Util.isNullOrEmptySpance(companyName)) {
        params.companyName = companyName;
    }

    var cardName = $("input[name='cardName']").val()
    if (!FlashPay.Util.isNullOrEmptySpance(cardName)) {
        params.cardName = cardName;
    }

    var startAmount = $("input[name='startAmount']").val()
    if (!FlashPay.Util.isNullOrEmptySpance(startAmount)) {
        params.startAmount = startAmount;
    }

    var endAmount = $("input[name='endAmount']").val()
    if (!FlashPay.Util.isNullOrEmptySpance(endAmount)) {
        params.endAmount = endAmount;
    }

    var clientAccountName = $("input[name='clientAccountName']").val()
    if (!FlashPay.Util.isNullOrEmptySpance(clientAccountName)) {
        params.clientAccountName = clientAccountName;
    }

    params.startTime = $("input[name='startTime']").val();
    params.endTime = $("input[name='endTime']").val();
    return params;
}

function replace_field(key) {

    var data = {
        "订单号": "Order#",
        "实际订单号": "Actual Order#",
        "公司名称": "Company Name",
        "银行名称": "Bank Name",
        "收款卡用户名": "Receipt Name",
        "银行卡号": "Card Number",
        "余额": "Balance",
        "收款金额": "Amount",
        "付款时间": "Payment Time",
        "客户银行": "Customer Bank",
        "客户姓名": "Customer Name",
        "客户卡号": "Customer Card#",
        "匹配单号": "Matching Order#",
        "备注": "Remarks",
        "机器ID": "Client ID",
    };

    var language = FlashPay.Util.Language();

    if (!FlashPay.Util.isNullOrEmptySpance(language) && language == "en") {
        return data[key];
    } else {
        return key;
    }
}

function doSearch() {

    var frozenColumns = [[
        { field: 'orderNo', title: replace_field('订单号'), width: 150, align: 'left' },
        { field: 'clientOrderNo', title: replace_field('实际订单号'), width: 200, align: 'left' },
        { field: 'companyName', title: replace_field('公司名称'), width: 100, align: 'left' },
        { field: 'bankName', title: replace_field('银行名称'), width: 100, align: 'left' },
        { field: 'cardName', title: replace_field('收款卡用户名'), width: 100, align: 'left' }
    ]];

    var columns = [[
        {
            field: 'cardNumber', title: replace_field('银行卡号'), width: 125, align: 'left',
            formatter: function (val, row) {
                return FlashPay.Util.SubCardNumber(val);
            }
        },
        {
            field: 'afterBalance', title: replace_field('余额'), width: 75, align: 'right',
            formatter: function (val, row) {
                return '<span class="bold">{0}</span>'.format(val);
            }
        },
        {
            field: 'amount', title: replace_field('收款金额'), width: 75, align: 'right',
            formatter: function (val, row) {
                return '<span class="bold">{0}</span>'.format(val);
            }
        },
        {
            field: 'operatingDate', title: replace_field('付款时间'), width: 130, align: 'left',
            formatter: function (val, row) {
                var result = "";
                if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                    result = val.replace("T", " ");
                }
                return result;
            }
        },
        { field: 'clientBankName', title: replace_field('客户银行'), width: 200, align: 'left' },
        { field: 'clientAccountName', title: replace_field('客户姓名'), width: 100, align: 'left' },
        {
            field: 'clientCardNumber', title: replace_field('客户卡号'), width: 125, align: 'left',
            formatter: function (val, row) {
                return FlashPay.Util.SubCardNumber(val);
            }
        },
        {
            field: 'matchOrderNo',
            title: replace_field('匹配单号'),
            width: 150,
            align: 'left',
            formatter: function (val, item) {
                var result = val;

                if (FlashPay.Util.isNullOrEmptySpance(val)) {
                    result = '<a class="btn btn-default btn-xs btn-danger " data-title="{0}-补单" data-modal="/view/receipt/receiptmakeup.html?orderNo={0}" data-width="500" data-height="700">补单</a>'.format(item.orderNo);
                }

                return result;
            }
        },
        { field: 'remark', title: replace_field('备注'), width: 200, align: 'left' },
        { field: 'vmClientID', title: replace_field('机器ID'), width: 250, align: 'left' }
    ]];

    $("#easyui-treegrid").datagrid({
        fit: false,
        loadMsg: '数据加载中，请稍后……',
        url: '/Payment/ReceiptList',
        queryParams: getParams(),
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        pageSize: pageSize,
        pageList: [15, 30, 50, 100, 1000],
        height: $(window).height() - 70,
        idField: 'orderNo',
        onLoadSuccess: function () {
            pageSize = $('#easyui-treegrid').datagrid('options').pageSize;
        },
        frozenColumns: frozenColumns,
        columns: columns
    });

}